package com.example.projectjava.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

//针对appUser表做SQL操作的类
@Repository
public class AddressDao {

    @Autowired
    JdbcTemplate jdbcTemplate;

    public  int insertAddress(String address_id,String recipient,String address,String phone){
        String sql = "insert into shopping_address(address_id,recipient,address,phone) values(?,?,?,?)";
        return    jdbcTemplate.update(sql,address_id,recipient,address,phone);
    }

    public  int deleteAddress(String address_id){
        String sql  = "DELETE from shopping_address where address_id=?";
        return  jdbcTemplate.update(sql,address_id);
    }

    public List<Map<String,Object>> queryAllAddress(){
        String sql = "select * from shopping_address";
        return  jdbcTemplate.queryForList(sql);
    }

    public int updateAddress(String address_id, String recipient, String address, String phone){
        String sql = "update shopping_address set recipient=?,address=?,phone=? where address_id=?";
        return  jdbcTemplate.update(sql,recipient,address,phone,address_id);
    }
}
